package com.aoxin.service.impl.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.aoxin.mapper.system.SlfAttachmentBizMapper;
import com.aoxin.model.system.SlfAttachmentBiz;
import com.aoxin.service.inter.system.AttachmentBizService;
import com.aoxin.util.ErrorUtil;

@Service("attachmentBizService")
public class AttachmentBizServiceImpl implements AttachmentBizService {

	@Autowired
	private SlfAttachmentBizMapper slfAttachmentBizMapper;

	@Override
	@Transactional
	public SlfAttachmentBiz insertAttachmentBiz(SlfAttachmentBiz attachmentBiz) {
		Assert.notNull(attachmentBiz, String.format(ErrorUtil.PARAMETER_NULL, "attachmentBiz"));
		if (null == attachmentBiz.getSequence()) {
			attachmentBiz.setSequence(this.slfAttachmentBizMapper.getNextSequence(attachmentBiz.getBizId()).intValue());
		}
		this.slfAttachmentBizMapper.insertSelective(attachmentBiz);
		return attachmentBiz;
	}

	@Override
	@Transactional
	public void deleteAttachmentBizs(List<Integer> attachmentIdBizs) {
		Assert.notNull(attachmentIdBizs, String.format(ErrorUtil.PARAMETER_NULL, "attachmentIdBizs"));
		this.deleteAttachmentBizs(attachmentIdBizs);
	}

	@Override
	@Transactional
	public void updateAttachmentBiz(SlfAttachmentBiz attachmentBiz) {
		Assert.notNull(attachmentBiz, String.format(ErrorUtil.PARAMETER_NULL, "attachmentBiz"));
		this.slfAttachmentBizMapper.updateByPrimaryKeySelective(attachmentBiz);
	}

	@Override
	public SlfAttachmentBiz getAttachment(Integer attachmentBizId) {
		Assert.notNull(attachmentBizId, String.format(ErrorUtil.PARAMETER_NULL, "attachmentBizId"));
		return this.slfAttachmentBizMapper.selectByPrimaryKey(attachmentBizId);
	}
}
